<html>
	<head>
		<title>Html-Qrcode Demo</title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link rel="stylesheet" type="text/css" href="../../css/mui.css"/>
	</head>
	<body>
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">签到</h1>
		</header>
	</body>
	<script src="../../js/mui.min.js"></script>
	<script>
		mui.plusReady(function() {
			startRecognize()
		});

		function startRecognize() {
			try {
				var filter;
				//自定义的扫描控件样式
				var styles = {
					top: '44px',
					left: '0px',
					width: '100%',
					height: '100%',
					position: 'static',
				}
				//扫描控件构造
				scan = plus.barcode.create('bcid', filter, styles);
				scan.onmarked = onmarked;
				scan.onerror = onerror;
				plus.webview.currentWebview().append(scan);
				scan.start();

			} catch (e) {
				alert("出现错误啦:\n" + e);
			}
		};

		function onerror(e) {
			alert(e);
		};

		function onmarked(type, result) {
			var text = '';
			switch (type) {
				case plus.barcode.QR:
					text = 'QR: ';
					break;
				case plus.barcode.EAN13:
					text = 'EAN13: ';
					break;
				case plus.barcode.EAN8:
					text = 'EAN8: ';
					break;
			}
			//扫描成功之后的处理
			mui.toast('扫描成功')
			console.log(JSON.stringify(result))
			mui.openWindow({
				url: 'sign.html',
				id: 'sign.html',
				extras: {
					scan: result
				},
				createNew: false, //是否重复创建同样id的webview，默认为false:不重复创建，直接显示
			})

		};
	</script>
</html>
